<?php
/**
 * 欢乐钓鱼模块微站定义
 *
 * @author likai
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');
define("RES", "../addons/game_fish/template/mobile/");
define("WEBRES", "../addons/game_fish/template/web/");
class Game_fishModuleSite extends WeModuleSite {
	public function doMobilerankinglist(){
		global $_W, $_GPC;
		$allconfig = $this->module['config'];
		$ownlist = pdo_fetchall("select * from ".tablename($this->modulename."_member")."where uid=:uid",array("uid"=>$_W['fans']['uid']));
		$orderlist = pdo_fetchall("select * from ".tablename($this->modulename."_member")." order by getallpoint desc");
		
		foreach($orderlist as $key=>$value){
			if($value[uid]==$_W['fans']['uid']){
				$orderid = $key+1;
				break;
			}
		}
		$historylist = pdo_fetchall("select * from ".tablename($this->modulename."_member")." order by getallpoint desc limit 0,".$allconfig['orderbannum']);
		include $this->template('rankinglist');
	}
	public function doMobilehistory(){
		global $_W, $_GPC;
		$allconfig = $this->module['config'];
		$historylist = pdo_fetchall("select * from ".tablename($this->modulename."_history")." where nickname=:nickname",array("nickname"=>$membernickname = $_W['fans']['nickname']));
		include $this->template('history');
	}
	public function doMobileRule(){
		global $_W, $_GPC;
		$allconfig = $this->module['config'];
		include $this->template('gamerule');
	}
	public function doMobilePoint(){
		global $_W, $_GPC;
		$scope = $_GPC['scope'];
		$gamefishtime = strtotime($_GPC['gamefishtime']);
		$memberuid = $_GPC['memberuid'];
		$membernickname = $_GPC['membernickname'];
		$memberphonenum = $_GPC['memberphonenum'];
		$memberavatar = $_GPC['memberavatar'];
		if($_GPC['onetimefreetime']!="test"){
			$onetimefreetime = $_GPC['onetimefreetime'];
			$hook = $_GPC['hook'];
			$betweenmeg = $onetimefreetime;
			$onetimefreetime = $hook;
			$hook = $betweenmeg;				
			$serialnum = $_GPC['serialnum'];
			$freetime = pdo_fetchcolumn("select freetime from ".tablename('gamefish_freelink')." where serialnum='".$serialnum."'");
			$cutfreetime = $freetime-$hook;
			pdo_update("gamefish_freelink",array('freetime'=>$hook),array('serialnum'=>$serialnum));
			$freeplaytime = pdo_fetchcolumn("select freeplaytime from ".tablename($this->modulename."_member")." where uid=".$_W['fans']['uid']);
			$freeplaytime2 = $freeplaytime-$cutfreetime;
			pdo_update("game_fish_member",array('freeplaytime'=>$freeplaytime2),array('uid'=>$_W['fans']['uid']));
		}
		$log = array(
			0 => $memberuid,
			1 => "欢乐钓鱼积分添加",
			3 => $memberuid,
			4 => '',
			5 => 1,
		);
		$successornot =  mc_credit_update($memberuid,"credit1",$scope,$log);
		pdo_query("insert into ".tablename($this->modulename.'_history')." (getpoint,nickname,phonenum,gamefinishtime,avatar) values (:getpoint,:nickname,:phonenum,:gamefinishtime,:avatar)",array(':getpoint'=>$scope,':nickname'=>$membernickname,':phonenum'=>$memberphonenum,':gamefinishtime'=>$gamefishtime,':avatar'=>$memberavatar));
		$uid=$_GPC["memberuid"];
		$nickname=$_GPC["membernickname"];
		$headimg=$_GPC["memberavatar"];
		$phonenum=$_GPC["memberphonenum"];
		$balance=$_GPC["balance"];
		$point=$_GPC["point"]+$scope;
		
		
		$lasttime=$_GPC["playtime"];
		$entertime=$lasttime;
		$status = 1;
		if(pdo_fetch("select * from ".tablename($this->modulename.'_member')." where uid=:uid",array(":uid"=>$_GPC['memberuid']))){
			$lastfishtime = pdo_fetchcolumn("select fishtime from ".tablename($this->modulename.'_member')." where uid=:uid",array(":uid"=>$_GPC['memberuid']));
			$fishtime=$lastfishtime+1;
			$lastpaypoint = pdo_fetchcolumn("select paypoint from ".tablename($this->modulename.'_member')." where uid=:uid",array(":uid"=>$_GPC['memberuid']));
			$paypoint=$lastpaypoint+$_GPC["payall"];
			$getpoint = pdo_fetchcolumn("select getallpoint from ".tablename($this->modulename.'_member')." where uid=:uid",array(":uid"=>$_GPC['memberuid']));
			$getallpoint = $scope+$getpoint;
			pdo_query("update ".tablename($this->modulename.'_member')." set `nickname`=:nickname,`headimg`=:headimg,`phonenum`=:phonenum,`balance`=:balance,`point`=:point,`getallpoint`=:getallpoint,`paypoint`=:paypoint,`fishtime`=:fishtime,`lasttime`=:lasttime,`status`=:status where uid=:uid",array(":nickname"=>$nickname,":headimg"=>$headimg,":phonenum"=>$phonenum,":balance"=>$balance,":point"=>$point,":getallpoint"=>$getallpoint,":paypoint"=>$paypoint,":fishtime"=>$fishtime,":lasttime"=>$lasttime,":status"=>$status,":uid"=>$uid));
		}else{
			$fishtime=1;
			$getallpoint = $scope;
			$paypoint=$_GPC["payall"];
			
			pdo_query("insert into ".tablename($this->modulename.'_member')." (uid,nickname,headimg,phonenum,balance,point,getallpoint,paypoint,fishtime,entertime,lasttime,status) values (:uid,:nickname,:headimg,:phonenum,:balance,:point,:getallpoint,:paypoint,:fishtime,:entertime,:lasttime,:status)",array(":uid"=>$uid,":nickname"=>$nickname,":headimg"=>$headimg,":phonenum"=>$phonenum,":balance"=>$balance,":point"=>$point,":getallpoint"=>$getallpoint,":paypoint"=>$paypoint,":fishtime"=>$fishtime,":entertime"=>$entertime,":lasttime"=>$lasttime,":status"=>$status));	
		}
		$openid=$_GPC['openid'];
		$this->sendMsg($this->createMobileUrl('fish'),$scope,$openid);
	}
	public function sendMsg($url,$getpoint,$openid){
		
		$cfg = $this->module['config'];
		$msgid = $cfg['MSGID']['success_msg'];
		
		if (!empty($msgid)){
			load()->model('mc');
			$text = '积分';
			$data = array(
					'first' => array(
							'value' => "尊敬的客户，恭喜您通过欢乐钓鱼成功获取积分",
					),
					'keyword1' => array(
							'value' =>  date('Y年m月d日',time()),
					),
					'keyword2' => array(
							'value' => $getpoint,
					),
					'remark' => array(
							'value' => "感谢您的支持！",
					)
			);
			$this->sendTemplateMsg($openid,$msgid,$data,$url);
		}
	}
	private function sendTemplateMsg($openid,$msgid,$data,$url,$topcolor = '#FF0000'){
		global $_W;
		if (stripos($url,'http://') === false){
			$url = $_W['siteroot'].str_replace('./','app/',$url.'&ajax=ajax');
		}
		load()->classs('weixin.account');
		$acid = pdo_fetchcolumn('select acid from '.tablename('account')." where uniacid={$_W['uniacid']}");
		
		$accObj = WeixinAccount::create($acid);
// 		var_dump(get_object_vars($accObj));exit;
		var_dump($accObj->sendTplNotice($openid,$msgid,$data,$url,$topcolor));
	}
	public function doWebQrmanager(){
		global  $_W , $_GPC;
		$page = max(1, intval($_GPC['page']));
		$psize = 10;
		$pindex = $psize*($page-1);
		
		$total = count(pdo_fetchall("select * from ".tablename($this->modulename."_playqr")));
		if($_GPC['op']=="delete"){
			$gameqrimgurl = pdo_fetchcolumn("select gameqrimgurl from ".tablename($this->modulename."_playqr")." where id=".$_GPC['id']);
			$gameqrnum = pdo_fetchcolumn("select gameqrnum from ".tablename($this->modulename."_playqr")." where id=".$_GPC['id']);
			load()->func("file");
			file_delete(MODULE_ROOT."/qrcode/".$gameqrnum.".png");
			pdo_query("delete from ".tablename($this->modulename."_playqr")." where id=".$_GPC['id']);
			message("二维码删除成功",$this->createWebUrl("qrmanager"));
		}
		
		if($_GPC['op']=="createqr"){
			$createqrnum = $_GPC['createqrnum'];
			$serialnumberarray = array();
			for($i=0;$i<intval($createqrnum);$i++){
				array_push($serialnumberarray,$this->Serialnumber());
			}
			$this->createQrcodes($serialnumberarray);
			message("批量生成二维码成功",$this->createWebUrl("qrmanager"));
		}
		if($_GPC['op']=="selectqr"){
			$qrusenickname = $_GPC['qrusenickname'];
			$qrusetime = $_GPC['qrusetime'];
			if($_GPC['qrusenickname']==""){
				$condition=" where usetime between ".strtotime($_GPC['qrusetime'][start])." and ".strtotime($_GPC['qrusetime'][end]);
			}else{
				$condition=" where gameqrusername like '%".$_GPC['qrusenickname']."%'"." and usetime between ".strtotime($_GPC['qrusetime'][start])." and ".strtotime($_GPC['qrusetime'][end]);
			}
		}
		$list = pdo_fetchall("select * from ".tablename($this->modulename."_playqr").$condition." limit ".$pindex.",".$psize);
		$total = count(pdo_fetchall("select * from ".tablename($this->modulename."_playqr").$condition));
	
		$pager = pagination($total,$pindex,$psize);
		include $this->template("web/qr");
	}
	public function createQrcode($serialnum){
		global  $_W;
		include 'phpqrcode.php';
		$q = "../addons/".$this->modulename."/qrcode/{$serialnum}.png";
		$qurl = $_W['siteroot']."addons/".$this->modulename."/qrcode/{$serialnum}.png";
		$url = $_W['siteroot']."app".substr($this->createMobileUrl('fish',array('op'=>'lottery','serialnum'=>$serialnum)),1);
		pdo_query("insert into ".tablename($this->modulename."_playqr")." (gameqrimgurl,qrurl,gameqrnum) value (:gameqrimgurl,:qrurl,:gameqrnum)",array(":gameqrimgurl"=>$qurl,":qrurl"=>$url,":gameqrnum"=>$serialnum));
		$errorCorrectionLevel = "L";
		$matrixPointSize = "4";
		QRcode::png($url, $q, $errorCorrectionLevel, $matrixPointSize);
		$links = array('uid'=>$id,'url'=>$url);
		return $s;
	}
	public function createQrcodes($serialnumarray){
		global  $_W;
		include 'phpqrcode.php';
		$errorCorrectionLevel = "L";
		$matrixPointSize = "4";
		foreach($serialnumarray as $key=>$value){
			$q[$key] = "../addons/".$this->modulename."/qrcode/{$value}.png";
			$qurl[$key] = $_W['siteroot']."addons/".$this->modulename."/qrcode/{$value}.png";
			$url[$key] = $_W['siteroot']."app".substr($this->createMobileUrl('fish',array('op'=>'lottery','serialnum'=>$value)),1);
			pdo_query("insert into ".tablename($this->modulename."_playqr")." (gameqrimgurl,qrurl,gameqrnum) value (:gameqrimgurl,:qrurl,:gameqrnum)",array(":gameqrimgurl"=>$qurl[$key],":qrurl"=>$url[$key],":gameqrnum"=>$value));
			QRcode::png($url[$key], $q[$key], $errorCorrectionLevel, $matrixPointSize);
		}

		
	}

	public function Serialnumber($check=true){
		if($check){
			$yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
			$orderSn = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99). substr(microtime(), 2, 5));
		}else{
			$yCode = array('M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
			$orderSn = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
		}
		return $orderSn;
	}
	public function doMobileFish() {
		global $_W, $_GPC;
		$allconfig = $this->module['config'];
		define("ATTRACHURL",$_W['attachurl']);
		//这个操作被定义用来呈现 功能封面
		if($_GPC['op']=="ajaxpic"){
			header('Content-Type: image/jpeg');
			echo MODULE_URL."icon.jpg";exit;
		}
		//第三方调用这个借口可以免费玩第三方规定的免费次数
		//格式举例：http://test.gznuoran.cn/app/index.php?i=2&c=entry&freenumber=3&op=ajaxplay&do=Fish&m=game_fish&serialnumber=???
		if($_GPC['op']=="ajaxreturn"){
			if(!$_GPC['freenumber']){
				echo "param freenumber cannot be none!";exit();
			}
			echo $_W['siteroot']."app/".substr($this->createMobileUrl("Fish",array("freenumber"=>$_GPC['freenumber'],"op"=>"ajaxplay","serialnumber"=>$_GPC['serialnum'])),2);exit();
		}
		
		if($_GPC['op']=="ajaxplay"){
			$freenumber = $_GPC['freenumber'];
			$freetime = $_GPC['freenumber'];
			
			$serialnumber = $_GPC['serialnum'];
			if(pdo_fetchcolumn('select serialnum from '.tablename('gamefish_freelink')." where serialnum='".$serialnumber."'")){
// 				echo "the link is used before";exit();
				$freetime = pdo_fetchcolumn('select freetime from '.tablename('gamefish_freelink')." where serialnum='".$serialnumber."'");
				$allfreetime = pdo_fetchcolumn('select allfreetime from '.tablename('gamefish_freelink')." where serialnum='".$serialnumber."'");
				$freeplaytime = pdo_fetchcolumn("select freeplaytime from ".tablename($this->modulename."_member")." where uid=".$_W['fans']['uid']);
// 				if($freetime<=-1){
// 					$usedtime = 1;
// 				}
			}else{
				$freenumber = $_GPC['freenumber'];
				pdo_insert("gamefish_freelink",array('serialnum'=>$serialnumber,"allfreetime"=>$freenumber,"freetime"=>$freenumber));
				$freeplaytime = pdo_fetchcolumn("select freeplaytime from ".tablename($this->modulename."_member")." where uid=".$_W['fans']['uid']);
				if($freeplaytime==-1){
					$freeplaytime = $freeplaytime+$freenumber+1;				
				}else{
					$freeplaytime = $freeplaytime+$freenumber;
				}
				pdo_update("game_fish_member",array('freeplaytime'=>$freeplaytime),array('uid'=>$_W['fans']['uid']));
			}
		}
		
		
		
		//二维码扫码逻辑
		if($_GPC['op']=="lottery"){
			$status = pdo_fetchcolumn("select status from ".tablename($this->modulename."_playqr")." where gameqrnum=:gameqrnum",array('gameqrnum'=>$_GPC['serialnum']));
			if($status!=1){
				pdo_query("update ".tablename($this->modulename."_playqr")." set `gameqrusername`=:gameqrusername,`gameqruseruid`=:gameqruseruid,`usetime`=:usetime,`status`=:status"." where gameqrnum=:gameqrnum",array(
						'gameqrusername'=>$_W['fans']['nickname'],
						'gameqruseruid'=>$_W['fans']['uid'],
						'usetime'=>time(),	
						'gameqrnum'=>$_GPC['serialnum'],
						'status'=>1
				));
				$addhooknumber = true;
			}else{
				$used=true;
			}
		}
		
		
		if(!$_GPC['taskid']){

			$countnum = pdo_fetch("select count(*) from ".tablename($this->modulename."_task")." where status=1");
			if($countnum['count(*)']==0){
				$alertornot = 0;
			}else{
				$alertornot = 1;
			}

			$activitytoitemidjson = pdo_fetchcolumn("select activitytoitemid from ".tablename($this->modulename."_activity")." where status=1");			
			$activitytoitemidarray = json_decode($activitytoitemidjson,true);
			$defaultgame = $activitytoitemidarray[0];
			if(!$defaultgame){
				$alert = 1;
			}
			$datalist = pdo_fetch("select * from ".tablename($this->modulename.'_item')." where itemname=:itemname",array("itemname"=>$defaultgame));
			if($_GPC['gamename']){
				$datalist = pdo_fetch("select * from ".tablename($this->modulename."_item")." where itemname=:itemname",array("itemname"=>$_GPC['gamename']));
				$alertornot = 1;
				$nowgamename = $_GPC['gamename'];
			}
			$dummylist = $datalist['dummy'];
			$dummylist = explode('，',$dummylist);
			$fishlist = json_decode($datalist['fishjson'],true);
			$fishlistjson = $datalist['fishjson'];
			$hooklist = json_decode($datalist['hookjson'],true);
			$noselect = 1;
			$tasktime = time();
		}else{
			if($_GPC['tasktime']){
				$tasktime = pdo_fetchcolumn("select tasktime from ".tablename($this->modulename."_member")." where uid=".$_GPC['uid']);
				
				if(!$tasktime){
					$tasktimearray = [];
					$tasktimeitem['taskid'] = $_GPC['taskid'];
					$tasktimeitem['lasttasktime'] = $_GPC['tasktime'];
					array_push($tasktimearray,$tasktimeitem);
					$tasktime = json_encode($tasktimearray);
				}else{
					$taskidarray = [];
					$tasktimearray = json_decode($tasktime,true);
					foreach ($tasktimearray as $key=>$value){
						array_push($taskidarray,$value['taskid']);
						if($value['taskid']==$_GPC['taskid']){
							$tasktimearray[$key]['lasttasktime']=$_GPC['tasktime'];
						}
					}
					if(!in_array($_GPC['taskid'],$taskidarray)){
						$tasktimeitem['taskid'] = $_GPC['taskid'];
						$tasktimeitem['lasttasktime'] = $_GPC['tasktime'];
						array_push($tasktimearray,$tasktimeitem);
					}
					$tasktime = json_encode($tasktimearray);
					
				}
				pdo_query("update ".tablename($this->modulename."_member")." set tasktime=:tasktime where uid=:uid",array(':uid'=>$_GPC['uid'],':tasktime'=>$tasktime));
				
				$entertaskid = pdo_fetchcolumn("select entertaskid from ".tablename($this->modulename."_member")." where uid=".$_GPC['uid']);
				$entertaskidarray = explode(",",$entertaskid);
				if(!in_array($_GPC['taskid'],$entertaskidarray)){
					array_push($entertaskidarray,$_GPC['taskid']);
					$entertaskid = implode(",",$entertaskidarray);
					pdo_query("update ".tablename($this->modulename."_member")." set entertaskid=:entertaskid where uid=:uid",array(':uid'=>$_GPC['uid'],':entertaskid'=>$entertaskid));
				}
				
				//task任务类型
				$tasktype = pdo_fetchcolumn("select tasktype from ".tablename($this->modulename."_task")." where id=".$_GPC['taskid']);

				if($tasktype==0){
					$firstplayget = pdo_fetchcolumn("select firstplayget from ".tablename($this->modulename."_task")." where id=".$_GPC['taskid']);
				}
				if($tasktype==1){
					
				}
				if($tasktype==2){
						
				}
			}
			$alertornot = 0;
			$taskid = $_GPC['taskid'];
			$firstplayget = pdo_fetchcolumn("select firstplayget from ".tablename($this->modulename.'_task')." where id=".$taskid);
			$datalist = pdo_fetch("select * from ".tablename($this->modulename.'_task')." as a left join ".tablename($this->modulename.'_item')." as b on (a.tasktoitemid = b.id)  where a.status=1 order by taskorder asc");
			$dummylist = $datalist['dummy'];
			$dummylist = explode('，',$dummylist);
			$fishlist = json_decode($datalist['fishjson'],true);
			$fishlistjson = $datalist['fishjson'];
			$hooklist = json_decode($datalist['hookjson'],true);
		}
		$historylist = pdo_fetchall("select * from ".tablename($this->modulename."_history")." order by gamefinishtime desc limit 0,5");
		$memberpoint = $_W['member']['credit1'];
		$memberuid = $_W['fans']['uid'];
		$membernickname = $_W['fans']['nickname'];
		$memberphonenum = $_W['member']['mobile'];
		$memberavatar = $_W['fans']['tag']['avatar'];
		$balance=$_W['member']['credit2'];
		$point=$_W['member']['credit1'];
		if(!$_GPC['op']=="ajaxplay"&&$_GPC['ajax']!="ajax"){
			$status = pdo_fetchcolumn("select status from ".tablename($this->modulename."_member")." where uid=".$memberuid);
			if($status==0){
				$inblacklist="in";
			}else{
				$inblacklist="out";
			}
		}else{
			$inblacklist="out";
		}
		$nowtime = time();

		include $this->template('index');
	}
	public function doMobileGetTask(){
		global $_W, $_GPC;
		$datalist = pdo_fetchall("select * from ".tablename($this->modulename.'_task')." order by taskorder asc");
		$tasktime = pdo_fetchcolumn("select tasktime from ".tablename($this->modulename.'_member')." where uid=".$_GPC['uid']);
		$tasktimearray = json_decode($tasktime,true);
		if($_GPC['uid']){
			$entertaskid = pdo_fetchcolumn("select entertaskid from ".tablename($this->modulename."_member")." where uid=".$_GPC['uid']);
			$entertaskidarray = explode(",",$entertaskid);
			foreach($datalist as $key=>$value){
				$lasttasktime=null;
				if(!$value['dayornot']){
					if(in_array($value['id'],$entertaskidarray)){
						$datalist[$key]['buttonstatus']="no";
					}else{
						$datalist[$key]['buttonstatus']="yes";
					}
				}else{
					if($tasktimearray){
						foreach($tasktimearray as $keys=>$values){
							if($values['taskid']==$value['id']){
								$lasttasktime = $values['lasttasktime'];
								break;
							}else{
								empty($lasttasktime);
							}
						}

					}else{
						empty($lasttasktime);
					}
					$onetimedaybegin = strtotime(date("Y-m-d",$lasttasktime));
					$onetimedayend = strtotime(date("Y-m-d",$lasttasktime+1*24*60*60));
					if($onetimedaybegin<$lasttasktime&&$lasttasktime<$onetimedayend){
						$datalist[$key]['buttonstatus']="dayfi";
					}else{
						$datalist[$key]['buttonstatus']="yes";
					}
				}
			}
		}
		echo json_encode($datalist);exit();
	}
	public function doWebItem() {	
		global $_W, $_GPC;
		$op = $_GPC['op'];
		$ha = $_GPC['ha'];
		if($op=="itemsetting"){
			
			$list = pdo_fetchall("select * from ".tablename($this->modulename.'_item')." order by ordernum asc");
			include $this->template('web/item');
			exit();
		}
		if($op=="itemtypeadd"){
			if($ha=="insert"){
				pdo_query("insert into ".tablename($this->modulename.'_itemtype')." (itemtypename) values (:typename)",array(':typename'=>$_GPC['typename']));
				message("添加分类成功",$this->createWebUrl("item"));
			}
			include $this->template('web/itemtypeadd');
			exit();
		}
		if($op=="itemtypedelete"){

			exit();
		}
		if($op=="itemtypeupdate"){
			$id=$_GPC[id];
			if ($ha=="update"){
				pdo_query("update ".tablename($this->modulename.'_itemtype')." set itemtypename=:typename where id=:id",array(':typename'=>$_GPC['typename'],':id'=>$_GPC[id]));
				message("添加分类成功",$this->createWebUrl("item"));
			}
			$dataitem = pdo_fetch("select * from ".tablename($this->modulename.'_itemtype')." where id=".$_GPC['id']);
			include $this->template('web/itemtypeupdate');
			exit();
		}
		$list = pdo_fetchall("select * from ".tablename($this->modulename.'_itemtype'));
		//这个操作被定义用来呈现 管理中心导航菜单
		include $this->template('web/itemtype');
	}
	public function doWebActivity() {
		global $_W, $_GPC;
		$datalist = pdo_fetchall("select * from ".tablename($this->modulename."_activity")." order by activityorder desc");
		include $this->template('web/activity');
	}
	public function doWebActivitydefault(){
		global $_W, $_GPC;
		pdo_query("update ".tablename($this->modulename."_activity")." set `status`=0");
		if(pdo_query("update ".tablename($this->modulename."_activity")." set `status`=1 where id=".$_GPC['id'])){
			message("修改默认活动成功",$this->createWebUrl('activity'));
		}
	}
	public function doWebActivityadd() {
		global $_W, $_GPC;
		
		$itemlist = pdo_fetchall("select * from ".tablename($this->modulename.'_item'));
		if(checksubmit()){
			pdo_query("insert into ".tablename($this->modulename."_activity")." (`activitytoitemid`,`activityname`,`activityorder`,`status`,`activityplayernum`) values (:activitytoitemid,:activityname,:activityorder,:status,:activityplayernum)",array(":activitytoitemid"=>htmlspecialchars_decode($_GPC[itemjson]),":activityname"=>$_GPC['activityname'],":activityorder"=>$_GPC['activityorder'],":status"=>$_GPC['status'],":activityplayernum"=>$_GPC['activityplayernum']));
			message("活动添加成功",$this->createWebUrl("activity"));
		}
		include $this->template('web/activityadd');
	}
	public function doWebActivitysetting() {
		global $_W, $_GPC;
		$itemlist = pdo_fetchall("select * from ".tablename($this->modulename.'_item'));
		$itemjson = pdo_fetchcolumn("select activitytoitemid from ".tablename($this->modulename.'_activity')." where id=".$_GPC['id']);
		$activitytoitemlist = json_decode(htmlspecialchars_decode($itemjson),true);
		$activitytoitemlistdata = array();
		foreach ($activitytoitemlist as $key=>$value){
			foreach ($itemlist as $keys=>$values){
				if($value==$values['itemname']){
					array_splice($itemlist, $keys, 1);
				}
				if($value['itemname']!=$values){
					array_push($activitytoitemlistdata,$values);
					break;
				}
			}
		}
		if(checksubmit()){
			$id = $_GPC[id];
					
			if(pdo_query("update ".tablename($this->modulename."_activity")." set `activitytoitemid`=:activitytoitemid,`activityname`=:activityname,`activityorder`=:activityorder,`status`=:status,`activityplayernum`=:activityplayernum where id=".$id,array('activitytoitemid'=>htmlspecialchars_decode($_GPC[itemjson]),'activityname'=>$_GPC['activityname'],'activityorder'=>$_GPC['activityorder'],'status'=>$_GPC['status'],'activityplayernum'=>$_GPC['activityplayernum']))){
				message("活动修改成功",$this->createWebUrl("activity"));
			}
		}
		$id = $_GPC[id];
		$data = pdo_fetch("select * from ".tablename($this->modulename."_activity")." where id=:id",array("id"=>$_GPC[id]));
		include $this->template('web/activitysetting');
	}
	public function doWebActivitydelete() {
		global $_W, $_GPC;
		$id = $_GPC['id'];
		if(pdo_query("delete from ".tablename($this->modulename."_activity")." where id=".$_GPC["id"])){
			message("删除成功",$this->createWebUrl("activity"));
		}
		exit();
	}
	public function doWebActivityorder() {
		global $_W, $_GPC;
		$activityorderlist = $_GPC['activityorder'];
		$activityidlist = $_GPC['activityid'];
		foreach($activityidlist as $keys=>$values){
			pdo_query("update ".tablename($this->modulename.'_activity')." set `activityorder`=:activityorder where id=".$values,array(":activityorder"=>$activityorderlist[$keys]));
		}
		message("修改排序成功");
		include $this->template('web/activity');
	}
	public function doWebMember() {
		global $_W, $_GPC;
		//这个操作被定义用来呈现 管理中心导航菜单
		$op = $_GET['op'];
		$page = max(1, intval($_GPC['page']));
		$pageitem = 10;
		if($op=="memberselect"){
			$membernickname = $_GPC[membernickname];
			$memberphonenum = $_GPC[memberphonenum];
			if($membernickname&&!$memberphonenum){
				$condition=" where nickname='".$membernickname."'";
			}
			if($memberphonenum&&!$membernickname){
				$condition=" where phonenum='".$memberphonenum."'";
			}
			if($memberphonenum&&$membernickname){
				$condition=" where nickname='".$membernickname."'"." and phonenum='".$memberphonenum."'";
			}
			if(!$memberphonenum&&!$membernickname){
				$condition="";
			}
			$page = max(1, intval($_GPC['page']));
			$psize = 10;
			$pindex = $psize*($page-1);
			$total = count(pdo_fetchall("select * from ".tablename($this->modulename."_member").$condition));
			
			$memberlist = pdo_fetchall("select * from ".tablename($this->modulename."_member").$condition." limit ".$pindex.",".$psize);
			$pager = pagination($total,$pindex,$psize);
			include $this->template('web/member');
			exit();
		}
		if($op=="membermanager"){
			$page = max(1, intval($_GPC['page']));
			$psize = 10;
			$pindex = $psize*($page-1);
			$total = count(pdo_fetchall("select * from ".tablename($this->modulename."_member")));
			$memberlist = pdo_fetchall("select * from ".tablename($this->modulename."_member")." limit ".$pindex.",".$psize);	
			$pager = pagination($total,$pindex,$psize);
			include $this->template('web/member');
			exit();
		}
		if($op=="selecthistory"){
			$page = max(1, intval($_GPC['page']));
			$pagestart = $pageitem*($page-1);
			$pageitem = 10;
			$condition = '';
			$nickname = $_GPC['nickname'];
			if (!$nickname) {
				$condition .= "";
			}else{
				$condition .= " where nickname like '%{$nickname}%'";
			}
			
			$historylist = pdo_fetchall("select * from ".tablename($this->modulename."_history").$condition." limit ".$pagestart.",".$pageitem);
			
			$historydata = pdo_fetchall("select * from ".tablename($this->modulename."_history").$condition);
			$itemall = count($historydata);
			$pager = pagination($itemall,$page,$pageitem);
			include $this->template('web/playhistory');
			exit();
		}	
		
		if(!$op||$op=="playhistory"){
			$historylist = pdo_fetchall("select * from ".tablename($this->modulename."_history"));
			$itemall = count($historylist);
			$pagestart = $pageitem*($page-1);
			$SQL = "select * from ".tablename($this->modulename."_history")." limit ".$pagestart.",".$pageitem;
		}
		$pager = pagination($itemall,$page,$pageitem);
		$historylist = pdo_fetchall($SQL);
	
		include $this->template('web/playhistory');
	}

	
	public function doWebGamesetting(){
		global $_W, $_GPC;
		$ha = $_GPC['ha'];
		$id = $_GPC['id'];
		if($_GPC['op']=="lahei"){
			if($_GPC['status']==1){
				pdo_query("update ".tablename($this->modulename."_member")." set `status`=0 where id=".$_GPC['id']);
				message("用户已拉入黑名单",$this->createWebUrl("member",array('op'=>'membermanager')));exit();
			}
			if($_GPC['status']==0){
				pdo_query("update ".tablename($this->modulename."_member")." set `status`=1 where id=".$_GPC['id']);
				message("用户已拉出黑名单",$this->createWebUrl("member",array('op'=>'membermanager')));exit();
			}
		}
		if($ha=="update"){
			if(empty($_GPC["itemtype"])){
				message("游戏项目分类不能为空");
			}
			if(empty($_GPC["itemname"])){
				message("游戏项目名字不能为空");
			}
			for($i=0;$i<count($_GPC['fishname']);$i++){
				$imgmsg = $this->myGetImageSize($_W['attachurl'].$_GPC['fishimgurl'][$i]);
				$datalist[] = array('fishheight'=>$imgmsg['height'],'fishwidth'=>$imgmsg['width'],'fishname'=>$_GPC['fishname'][$i],'fishimgurl'=>$_GPC['fishimgurl'][$i],'fishchance'=>$_GPC['fishchance'][$i],'fishpoint'=>$_GPC['fishpoint'][$i]);
			
			}
			
			for($i=0;$i<count($_GPC['hookimgurl']);$i++){
				$hookdatalist[] = array('hookimgurl'=>$_GPC['hookimgurl'][$i],'hookpaypoint'=>$_GPC['hookpaypoint'][$i]);
			}

			$fishjson = json_encode($datalist);
			$hookjson = json_encode($hookdatalist);
			pdo_query("update ".tablename($this->modulename."_item")." set `recommend`=:recommend,`typeid`=:typeid,`itemname`=:itemname,`ordernum`=:ordernum,`joinnum`=:joinnum,`gametime`=:gametime,`gamemessage`=:gamemessage,`gamebgimgurl`=:gamebgimgurl,`status`=:status,`frameskip`=:frameskip,`bigestfishjoltingrate`=:bigestfishjoltingrate,`smallestfishjoltingrate`=:smallestfishjoltingrate,`bigestfishupanddownamplitude`=:bigestfishupanddownamplitude,`smallestestfishupanddownamplitude`=:smallestestfishupanddownamplitude,`lowestfishswimheight`=:lowestfishswimheight,`heightestfishswimheight`=:heightestfishswimheight,`fishspeed`=:fishspeed,`fishdencity`=:fishdencity,`fishjson`=:fishjson,`onetimepay`=:onetimepay,`hookjson`=:hookjson where id=".$_GPC[id],array(
					':recommend'=>$_GPC[recommend],
					':typeid'=>$_GPC[itemtype],
					':itemname'=>$_GPC[itemname],
					':ordernum'=>$_GPC[ordernumber],
					':joinnum'=>$_GPC[joinnum],
						
					':gametime'=>$_GPC[gamebetweentime],
					':gamemessage'=>$_GPC[gamemessage],
					':gamebgimgurl'=>$_GPC[gamebgimgurl],
			
					':status'=>$_GPC[groundingornot],
					':frameskip'=>$_GPC[framenumber],
					':bigestfishjoltingrate'=>$_GPC[shocklvbegin],
					':smallestfishjoltingrate'=>$_GPC[shocklvend],
					':bigestfishupanddownamplitude'=>$_GPC[updownrangeend],
					':smallestestfishupanddownamplitude'=>$_GPC[updownrangebegin],
					':lowestfishswimheight'=>$_GPC[swimlowest],
					':heightestfishswimheight'=>$_GPC[swimtopest],
					':fishspeed'=>$_GPC[fishspeed],
					':fishdencity'=>$_GPC[fishdencity],
					':fishjson'=>$fishjson,
					':onetimepay'=>$_GPC[onetimepay],
					':hookjson'=>$hookjson,
			));
			message("修改成功",$this->createWebUrl("gamesetting",array(id=>$id)));
		}
		$typelist = pdo_fetchall("select * from ".tablename($this->modulename.'_itemtype'));
		$list = pdo_fetch("select * from ".tablename($this->modulename."_item")." where id=".$_GPC[id]);
		$fisharray = json_decode($list['fishjson'],true);
		$hookarray = json_decode($list['hookjson'],true);
		$fisharraylength = count($fisharray);
		include $this->template('web/gamesetting');
	}
	public function doWebGameadd(){
		global $_W, $_GPC;
		$ha=$_GPC['ha'];
		$typelist = pdo_fetchall("select * from ".tablename($this->modulename.'_itemtype'));

		
		if($ha=="add"){
			if(empty($_GPC["itemtype"])){
				message("游戏项目分类不能为空");
			}
			if(empty($_GPC["itemname"])){
				message("游戏项目名字不能为空");
			}
			
			for($i=0;$i<count($_GPC['fishname']);$i++){
				$imgmsg = $this->myGetImageSize($_W['attachurl'].$_GPC['fishimgurl'][$i]);
				$datalist[] = array('fishheight'=>$imgmsg['height'],'fishwidth'=>$imgmsg['width'],'fishname'=>$_GPC['fishname'][$i],'fishimgurl'=>$_GPC['fishimgurl'][$i],'fishchance'=>$_GPC['fishchance'][$i],'fishpoint'=>$_GPC['fishpoint'][$i]);
			
			}
			for($i=0;$i<count($_GPC['hookimgurl']);$i++){
				$hookdatalist[] = array('hookimgurl'=>$_GPC['hookimgurl'][$i],'hookpaypoint'=>$_GPC['hookpaypoint'][$i]);
			}

			$hookjson = json_encode($hookdatalist);
			$fishjson = json_encode($datalist);
			pdo_query("insert into ".tablename($this->modulename."_item")." (`recommend`,`typeid`,`itemname`, `ordernum`, `joinnum`,`gametime`,`gamemessage`,`gamebgimgurl`,`status`, `frameskip`, `bigestfishjoltingrate`, `smallestfishjoltingrate`, `bigestfishupanddownamplitude`, `smallestestfishupanddownamplitude`, `lowestfishswimheight`, `heightestfishswimheight`, `fishspeed`, `fishdencity`, `fishjson`,`onetimepay`,`hookjson`) values (:recommend,:typeid,:itemname,:ordernum,:joinnum,:gametime,:gamemessage,:gamebgimgurl,:status,:frameskip,:bigestfishjoltingrate,:smallestfishjoltingrate,:bigestfishupanddownamplitude,:smallestestfishupanddownamplitude,:lowestfishswimheight,:heightestfishswimheight,:fishspeed,:fishdencity,:fishjson,:onetimepay,:hookjson)",array(
				':recommend'=>$_GPC[recommend],
				':typeid'=>$_GPC[itemtype],
				':itemname'=>$_GPC[itemname],
				':ordernum'=>$_GPC[ordernumber],
				':joinnum'=>$_GPC[joinnum],	
					
				':gametime'=>$_GPC[gamebetweentime],
				':gamemessage'=>$_GPC[gamemessage],
				':gamebgimgurl'=>$_GPC[gamebgimgurl],	
				
				':status'=>$_GPC[groundingornot],
				':frameskip'=>$_GPC[framenumber],
				':bigestfishjoltingrate'=>$_GPC[shocklvbegin],
				':smallestfishjoltingrate'=>$_GPC[shocklvend],
				':bigestfishupanddownamplitude'=>$_GPC[updownrangeend],
				':smallestestfishupanddownamplitude'=>$_GPC[updownrangebegin],
				':lowestfishswimheight'=>$_GPC[swimlowest],
				':heightestfishswimheight'=>$_GPC[swimtopest],
				':fishspeed'=>$_GPC[fishspeed],
				':fishdencity'=>$_GPC[fishdencity],
				':fishjson'=>$fishjson,	
				':onetimepay'=>$_GPC[onetimepay],
				':hookjson'=>$hookjson,
			));
			
			message("游戏项目创建成功",$this->createWebUrl("item",array('op'=>'itemsetting')));
		}
		include $this->template('web/gameadd');
	}
	public function doWebGamedelete(){
		global $_W, $_GPC;
		pdo_query("delete from ".tablename($this->modulename."_item")." where id=".$_GPC["id"]);
		message("删除成功",$this->createWebUrl("item",array('op'=>'itemsetting')));
		include $this->template('web/item');
	}
	public function doWebGameorder(){
		global $_W, $_GPC;
		$gameorderlist = $_GPC['gameorder'];
		$gameidlist = $_GPC['gameid'];
		foreach($gameidlist as $keys=>$values){
			pdo_query("update ".tablename($this->modulename.'_item')." set `ordernum`=:ordernum where id=".$values,array(":ordernum"=>$gameorderlist[$keys]));
		}
		message("修改排序成功");
		include $this->template('web/item');
	}
	public function doWebTask() {
		global $_W, $_GPC;
		//这个操作被定义用来呈现 管理中心导航菜单
		
		$list = pdo_fetchall("select * from ".tablename($this->modulename."_task")." order by taskorder asc");
		include $this->template('web/task');
	}
	public function doWebTaskadd(){
		global $_W, $_GPC;
		for($i=0;$i<count($_GPC['fishname']);$i++){
			$datalist[] = array('fishname'=>$_GPC['fishname'][$i],'fishnum'=>$_GPC['fishnum'][$i],'fishgetpoint'=>$_GPC['fishgetpoint'][$i]);
		}
		$taskfishjson = json_encode($datalist);
		if(checksubmit()){
			pdo_query("insert into ".tablename($this->modulename."_task")." (`taskname`, `taskorder`, `taskheadimg`, `taskmessage`, `tasktoitemid`, `gamebegintime`, `gameendtime`,`dummy`,`status`,`dayornot`,`firstplayget`,`tasktype`,`taskfishjson`) values (:taskname,:taskorder,:taskheadimg,:taskmessage,:tasktoitemid,:gamebegintime,:gameendtime,:dummy,:status,:dayornot,:firstplayget,:tasktype,:taskfishjson)",array(
				":taskname"=>$_GPC['taskname'],
					":taskorder"=>$_GPC['taskorder'],
					":taskheadimg"=>$_GPC['taskheadimg'],
					":taskmessage"=>$_GPC['taskmessage'],
					":tasktoitemid"=>$_GPC['tasktoitemid'],
					":taskname"=>$_GPC['taskname'],
					":gamebegintime"=>$_GPC['betweentime']['start'],
					":gameendtime"=>$_GPC['betweentime']['end'],
					":dummy"=>$_GPC['dummy'],
					":status"=>$_GPC['status'],
					":dayornot"=>$_GPC['everyday'],
					":firstplayget"=>$_GPC['firstplayget'],
					":tasktype"=>$_GPC['tasktype'],
					":taskfishjson"=>$taskfishjson,
			));
			message("添加任务成功",$this->createWebUrl('task'));
		}
		$itemlist = pdo_fetchall("select * from ".tablename($this->modulename.'_item'));
		
		include $this->template('web/taskadd');
	}
	public function doWebTasksetting(){
		global $_W, $_GPC;
		$id = $_GPC[id];
		
		for($i=0;$i<count($_GPC['fishname']);$i++){
			$datalist[] = array('fishname'=>$_GPC['fishname'][$i],'fishnum'=>$_GPC['fishnum'][$i],'fishgetpoint'=>$_GPC['fishgetpoint'][$i]);	
		}
		$taskfishjson = json_encode($datalist);
		if(checksubmit()){
			pdo_query("update ".tablename($this->modulename."_task")." set `taskname`=:taskname,`taskorder`=:taskorder,`taskheadimg`= :taskheadimg,`taskmessage`= :taskmessage,`tasktoitemid`= :tasktoitemid,`gamebegintime`= :gamebegintime,`gameendtime`= :gameendtime,`dummy`=:dummy,`status`= :status,`dayornot`= :dayornot,`firstplayget`= :firstplayget,`tasktype`=:tasktype,`taskfishjson`=:taskfishjson where id=".$id,array(
				":taskname"=>$_GPC['taskname'],
				":taskorder"=>$_GPC['taskorder'],
				":taskheadimg"=>$_GPC['taskheadimg'],
				":taskmessage"=>$_GPC['taskmessage'],
				":tasktoitemid"=>$_GPC['tasktoitemid'],
				":taskname"=>$_GPC['taskname'],
				":gamebegintime"=>$_GPC['betweentime']['start'],
				":gameendtime"=>$_GPC['betweentime']['end'],
				":dummy"=>$_GPC['dummy'],
				":status"=>$_GPC['status'],
				":dayornot"=>$_GPC['everyday'],
				":firstplayget"=>$_GPC['firstplayget'],
				":tasktype"=>$_GPC['tasktype'],
				":taskfishjson"=>$taskfishjson,
			));
			message("任务修改成功",$this->createWebUrl('tasksetting',array('id'=>$id)));
		}
		$itemlist = pdo_fetchall("select * from ".tablename($this->modulename.'_item'));
		$list = pdo_fetch("select * from ".tablename($this->modulename."_task")." where id=".$_GPC[id]);
	
		$taskfisharray = json_decode($list['taskfishjson'],true);
		
		include $this->template('web/tasksetting');
	}
	public function doWebGamefishlist(){
		global $_W, $_GPC;
		$fishjson = pdo_fetchcolumn("select fishjson from ".tablename($this->modulename."_item")." where id=".$_GPC[id]);
		echo $fishjson;
		exit();
	
	}
	public function doWebTaskdelete(){
		global $_W, $_GPC;
		$id = $_GPC[id];
		pdo_query("delete from ".tablename($this->modulename."_task")." where id=".$id);
		message("删除成功",$this->createWebUrl('task'));
		include $this->template('web/task');
		
	}
	public function doWebTaskorder(){
		global $_W, $_GPC;
		$taskorderlist = $_GPC['taskorder'];
		$taskidlist = $_GPC['taskid'];
		foreach($taskidlist as $keys=>$values){
			pdo_query("update ".tablename($this->modulename.'_task')." set `taskorder`=:taskorder where id=".$values,array(":taskorder"=>$taskorderlist[$keys]));
		}
		message("修改排序成功");
		include $this->template('web/task');
		
	}
	
	
	
	
	
	function myGetImageSize($url, $type = 'curl', $isGetFilesize = false)
	{
		// 若需要获取图片体积大小则默认使用 fread 方式
		$type = $isGetFilesize ? 'fread' : $type;
		 
		if ($type == 'fread') {
			// 或者使用 socket 二进制方式读取, 需要获取图片体积大小最好使用此方法
			$handle = fopen($url, 'rb');
			 
			if (! $handle) return false;
			 
			// 只取头部固定长度168字节数据
			$dataBlock = fread($handle, 168);
		}
		else {
			// 据说 CURL 能缓存DNS 效率比 socket 高
			$ch = curl_init($url);
			// 超时设置
			curl_setopt($ch, CURLOPT_TIMEOUT, 5);
			// 取前面 168 个字符 通过四张测试图读取宽高结果都没有问题,若获取不到数据可适当加大数值
			curl_setopt($ch, CURLOPT_RANGE, '0-167');
			// 跟踪301跳转
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			// 返回结果
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			 
			$dataBlock = curl_exec($ch);
			 
			curl_close($ch);
			 
			if (! $dataBlock) return false;
		}
		 
		// 将读取的图片信息转化为图片路径并获取图片信息,经测试,这里的转化设置 jpeg 对获取png,gif的信息没有影响,无须分别设置
		// 有些图片虽然可以在浏览器查看但实际已被损坏可能无法解析信息
		$size = getimagesize('data://image/jpeg;base64,'. base64_encode($dataBlock));
		if (empty($size)) {
			return false;
		}
		 
		$result['width'] = $size[0];
		$result['height'] = $size[1];
		 
		// 是否获取图片体积大小
		if ($isGetFilesize) {
			// 获取文件数据流信息
			$meta = stream_get_meta_data($handle);
			// nginx 的信息保存在 headers 里，apache 则直接在 wrapper_data
			$dataInfo = isset($meta['wrapper_data']['headers']) ? $meta['wrapper_data']['headers'] : $meta['wrapper_data'];
			 
			foreach ($dataInfo as $va) {
				if ( preg_match('/length/iU', $va)) {
					$ts = explode(':', $va);
					$result['size'] = trim(array_pop($ts));
					break;
				}
			}
		}
		 
		if ($type == 'fread') fclose($handle);
		 
		return $result;
	}
}